var e = require;
var t = module;
var o = exports;
var n = o;
Object.defineProperty(n, "__esModule", {value: !0});
var i = e("ADAssetsManager"),
    a = (function () {
        function e() {
            (this._customStyle = null),
                (this._nativeBannerDisplayState = !1),
                (this._nativeBannerDisplayTag = !0),
                (this._isLoadComplete = !1),
                (this._loadAutoShow = !1),
                (this._isConsume = !1),
                (this._onLoadCallbackRef = null),
                (this._onResizeCallbackRef = null),
                (this._onErrorCallbackRef = null),
                (this._nativeBanner = null),
                (this._adData = null);
        }
        return (
            (e.prototype.init = function () {
                console.log("nativeBanner init"),
                    (this._onLoadCallbackRef = this.onNativeBannerLoad.bind(this)),
                    (this._onErrorCallbackRef = this.onNativeBannerError.bind(this)),
                    this.createNativeBanner(!1);
            }),
            (e.prototype.createNativeBannerNode = function () {
                cc.isValid(this._nativeBanner) && (this._nativeBanner.destroy(), (this._nativeBanner = null)),
                    (this._nativeBanner = i.default.instance.createNodeByPreloading(
                        i.adAssetsMap.prefabs.NativeBanner
                    )),
                    (this._nativeBanner.zIndex = cc.macro.MAX_ZINDEX),
                    this._nativeBanner
                        .getChildByName("content")
                        .getChildByName("btn_close")
                        .on("click", this.onClickClose, this),
                    this._nativeBanner.getChildByName("content").on("click", this.onClickAD, this);
            }),
            (e.prototype.destroyNativeBannerNode = function () {
                cc.isValid(this._nativeBanner) && (this._nativeBanner.destroy(), (this._nativeBanner = null));
            }),
            (e.prototype.showNativeBanner = function (e, t) {
                console.log("showNativeBanner", e),
                    (this._customStyle = e),
                    (this._showCallback = t),
                    (this._nativeBannerDisplayState = !0);
            }),
            (e.prototype.hideNativeBanner = function (e) {
                console.log("hideNativeBanner", e), (this._nativeBannerDisplayState = !1), (this._showCallback = null);
            }),
            (e.prototype.setNativeBannerDisplayTag = function (e) {
                if ((console.log("setNativeBannerDisplayTag", e), this._nativeBannerDisplayTag != e))
                    if (((this._nativeBannerDisplayTag = e), e))
                        this._nativeBannerDisplayState && this.showNativeBanner(this._customStyle, this._showCallback);
                    else {
                        var t = this._nativeBannerDisplayState;
                        this.hideNativeBanner(!1), (this._nativeBannerDisplayState = t);
                    }
            }),
            (e.prototype.destroyNativeBanner = function () {
                console.log("destoryNativeBanner"),
                    (this._customStyle = null),
                    (this._showCallback = null),
                    (this._nativeBannerDisplayState = !1),
                    (this._isLoadComplete = !1),
                    (this._loadAutoShow = !1),
                    (this._isConsume = !1),
                    this.destroyNativeBannerNode();
            }),
            (e.prototype.setAdData = function (e, t, o) {
                var n = this;
                console.log("setAdData", e, t, o),
                    cc.isValid(this._nativeBanner) &&
                        (e &&
                            cc.loader.load({url: e, type: "png"}, function (e, t) {
                                if (e) console.error("原生banner icon加载失败");
                                else {
                                    var o = new cc.SpriteFrame(t);
                                    o
                                        ? (n._nativeBanner
                                              .getChildByName("content")
                                              .getChildByName("ad_icon")
                                              .getComponent(cc.Sprite).spriteFrame = o)
                                        : console.error("原生banner icon加载失败");
                                }
                            }),
                        (this._nativeBanner
                            .getChildByName("content")
                            .getChildByName("lab_title")
                            .getComponent(cc.Label).string = t || ""),
                        (this._nativeBanner
                            .getChildByName("content")
                            .getChildByName("lab_dest")
                            .getComponent(cc.Label).string = o || ""));
            }),
            (e.prototype.onClickClose = function () {
                this.destroyNativeBanner(), this.createNativeBanner(!1);
            }),
            e
        );
    })();
n.default = a;
